﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FloatToBinary
{

    public partial class MainForm : Form
    {

        public MainForm()
        {
            InitializeComponent();
        }

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            //if (txtFloat.Text == "") txtFloat.Text = "0";
            //double initialValue = Convert.ToDouble(txtFloat.Text);

            float tempValue;
            if ((!float.TryParse(txtFloat.Text, out tempValue)) | (txtFloat.Text == ""))
            {
                MessageBox.Show("Float please!");
                txtFloat.Text = "";
                return;
            }
            FloatValue newValue = new FloatValue(txtFloat.Text);
            lblSign.Text = newValue.Sign;
            lblExponent.Text = newValue.Exponent;
            lblMantissa.Text = newValue.Mantissa;
            lblInvertedToFloat.Text = newValue.InvertedBinaryToFloat;

            /*MessageBox.Show(string.Format("Mantissa={0}\nExponent={1}\nExponent={2}",
                newValue.Mantissa,
                newValue.Exponent,
                newValue.GetExponent()));*/
        }

        private void txtFloat_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar == '.') | (e.KeyChar == ',')) e.KeyChar = DecimalSeparator.Separator;
        }

        
    }
}
